package com.flavors.ifly.hencoderplus;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;

/**
 *
 */
public class TestView extends View {
    Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);//抗锯齿
    Path path = new Path();//路径

    public TestView(Context context) {
        super(context);

    }

    public TestView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        // TODO: 2020/5/22 通过坐标绘制
        paint.setTextSize(80);
        paint.setColor(Color.RED);
//        canvas.drawLine(100, 100, 200, 200, paint);
//        canvas.drawCircle(getWidth() / 2, getHeight() / 2, Utils.dp2Px(20), paint);//这里使用dp 转为px 因为代码里用的是px，这里将dp转为px是为了适配不同手机20是dp,不同手机转化后的px值不同
        // TODO: 2020/5/22 通过路径绘制
//        path.setFillType(Path.FillType.WINDING);//顺时针逆时针 不规则图形用到
//        canvas.drawPath(path,paint);

    }

    /**
     * 在尺寸变了时才会调用,
     *
     * @param w
     * @param h
     * @param oldw
     * @param oldh
     */
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
        path.reset();//清除绘制的
        path.addRect(getWidth()/2,getHeight()/2,100,100, Path.Direction.CCW);//画矩形
        path.addCircle(getWidth()/2,getHeight()/2,150, Path.Direction.CCW);
    }

    /**
     * 测量
     *
     * @param widthMeasureSpec
     * @param heightMeasureSpec
     */
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    /**
     * 尺存改变时调用
     *
     * @param changed
     * @param left
     * @param top
     * @param right
     * @param bottom
     */
    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
    }
}

